package com.project.service.impl;

import com.project.bean.CutPageBean;
import com.project.bean.RoomBean;
import com.project.dao.IFacilitiesDao;
import com.project.dao.IRoomDao;
import com.project.dao.IStudentDao;
import com.project.dao.impl.FacilitiesDaoImpl;
import com.project.dao.impl.RoomDaoImpl;
import com.project.dao.impl.StudentDaoImpl;
import com.project.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements IRoomService {
    @Autowired
    private IRoomDao dao ;
    @Autowired
    private IStudentDao dao1 ;
    @Autowired
    private IFacilitiesDao dao2 ;
    @Override
    public CutPageBean<RoomBean> findByItem(Integer pageNo, String roomName, String roomState, String into, String roomSex) {
        return dao.findByItem(pageNo,roomName,roomState,into,roomSex);
    }

    @Override
    public RoomBean findById(Integer id) {
        RoomBean room = dao.findById(id);
        room.setStudentList(dao1.findByRoomId(id));
        return room;
    }

    @Override
    public boolean del(Integer id) {
        if (dao1.countByRoom(id)==0){
            dao.del(id);
            dao2.delRoom(id);
            return true;
        }else {
            return false;
        }

    }

    @Override
    public void add(RoomBean room) {
        dao.add(room);
    }

    @Override
    public List<RoomBean> findBySex(String sex) {

        return dao.findBySex(sex);
    }
}
